﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports Oracle.DataAccess.Client

Public Class Datos
    Private Const CadenaConexion As String = "USER ID=SIEGRE;PASSWORD=SIEGRE;DATA SOURCE=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = LOCALHOST)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = XE)));MIN POOL SIZE=2;DECR POOL SIZE=2;CONNECTION TIMEOUT=60;CONNECTION LIFETIME=120"
    Public Shared Function RegresarDatos(ByVal sentencia As String) As DataTable
        'Dim Cadena As String = ConfigurationManager.AppSettings("CadenaConexion")
        Dim tabla As New DataTable
        Dim conexion As New OracleConnection
        Dim comando As New OracleCommand
        conexion.ConnectionString = CadenaConexion
        'conexion.ConnectionString = Cadena
        comando = conexion.CreateCommand
        comando.Connection.Open()
        comando.CommandText = sentencia
        Dim adaptador As New OracleDataAdapter
        adaptador.SelectCommand = comando
        adaptador.Fill(tabla)
        comando.Connection.Close()
        Return tabla
    End Function

    Public Shared Function EjecutarSentencia(ByVal sentencia As String) As String
        Dim conexion As New OracleConnection
        Dim comando As New OracleCommand
        Dim numFilas As String
        conexion.ConnectionString = CadenaConexion
        comando = conexion.CreateCommand
        comando.Connection.Open()
        comando.CommandText = sentencia
        numFilas = comando.ExecuteNonQuery()
        comando.Connection.Close()
        numFilas = "Numero de Filas Afectadas: [" & numFilas & "]"
        Return numFilas
    End Function

    Public Shared Function CrearComando() As OracleCommand
        Dim conexion As New OracleConnection
        Dim comando As New OracleCommand
        conexion.ConnectionString = CadenaConexion
        comando = conexion.CreateCommand
        comando.CommandType = CommandType.Text
        Return comando
    End Function

    Public Shared Function EjecutarSentencia(ByVal comando As OracleCommand) As String
        Dim conexion As New OracleConnection
        Dim numFilas As String
        comando.Connection.Open()
        numFilas = comando.ExecuteNonQuery()
        comando.Connection.Close()
        numFilas = "Numero de Filas Afectadas: " & numFilas
        Return numFilas
    End Function
End Class
